// pages/msg_yield_details/msg_yield_details.js
let app =  getApp();
var my_lid = ''
  
Page({

    /**
     * 页面的初始数据
     */
    data: {
        array1:[
            {
                'LNAME':'一班'
            },
            {
                'LNAME':'二班'
            },
            {
                'LNAME':'三班'
            },
            {
                'LNAME':'四班'
            },
            {
                'LNAME':'五班'
            },
        ],
        zhuangtai:false,
        my_table: [],
        lpone: "https://www.hanliangroup.com:8443/image/UserImage/"
    },
    bindPickerChange1(e) { // 车间
        this.setData({
            index1: e.detail.value,
        })
        for(var i = 0 ; i < this.data.array1.length;i ++) {
            if(i == e.detail.value) {
                this.data.table[0].LBANCI = this.data.array1[i].LNAME
                this.setData({
                    table:this.data.table
                })
            }
        }
    },
    // ListTouch触摸开始
    ListTouchStart(e) {
        this.setData({
            ListTouchStart: e.touches[0].pageX
        })
    },
    // ListTouch计算方向
    ListTouchMove(e) {
        this.setData({
            ListTouchDirection: e.touches[0].pageX - this.data.ListTouchStart > 0 ? 'right' : 'left'
        })
    },
    // ListTouch计算滚动
    ListTouchEnd(e) {
        if (this.data.ListTouchDirection == 'left') {
            this.setData({
                modalName: e.currentTarget.dataset.target
            })
        } else {
            this.setData({
                modalName: null
            })
        }
        this.setData({
            ListTouchDirection: null
        })
    },
    update_details(e){
        wx.navigateTo({
            url: '../msg_yield_add_details/msg_yield_add_details?list=' + '2'
        })
    },
    yield_add() { // 添加产量录入明细信息
        if (this.data.zhuangtai == true) {

        } else {
            wx.navigateTo({
                url: '../msg_yield_add_details/msg_yield_add_details'
            })
        }
    },
    Submission(e){
        let that = this
        wx.request({
            url: 'https://' + app.globalData.url + '/Contract/findContractTJ',
            data: {
                'MODULENO':300201,
                'LID':this.data.table[0].LID,
                'STATERUN':this.data.table[0].LSTATERUN,
                'LUSERCODE':app.globalData.lusercode,
            },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            header: {
                'content-type': 'application/x-www-form-urlencoded'
            },
            success: function (res) {
                if(res.data.success == true) {
                    wx.navigateBack({
                        delta: 1
                    })
                    wx.showToast({
                        title: '成功',
                        icon: 'success',
                        duration: 2000
                    })
                } else {
                    wx.showToast({
                        title: '失败',
                        icon: 'none',
                        duration: 2000
                    })
                }
            },
            fail: function (res) {
                that.setData({
                    loadModal: false
                })
                wx.showModal({
                    title: '提示',
                    content: '访问服务器出错',
                    showCancel: false,
                    confirmText: '确定',
                    success(res) {
                        if (res.confirm) {

                        }
                    }
                })
            },
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        let that = this
        console.log(options.lstaterun)
        app.globalData.lstaterun = options.lstaterun
        if(app.globalData.lstaterun == 12 || app.globalData.lstaterun == 1) {
            that.setData({
                zhuangtai:true,
            })
        }
        wx.request({
            url: 'https://' + app.globalData.url + '/SaleOrder/findSaleOrderAll',
            data: {
                LID: options.lid
            },
            method: 'GET',
            dataType: 'json',
            responseType: 'text',
            header: {
                'content-type': 'application/json;charset=utf-8'
            },
            success: function (res) {
                if (res.data.success) {
                    if (res.data.obj[0].LSEQ == '' || res.data.obj[0].LSEQ == undefined) {
                        that.setData({
                            table: res.data.obj
                        })
                        my_lid = that.data.table[0].LID
                        for(var i = 0 ; i < that.data.array1.length; i ++) {
                            console.log(that.data.table[0].LBANCI)
                            if(that.data.table[0].LBANCI == that.data.array1[i].LNAME) {
                                that.setData({
                                    index1:i
                                })
                            }
                        }
                    } else {
                        that.setData({
                            table: res.data.obj,
                            my_table: res.data.obj
                        })
                        for(var i = 0 ; i < that.data.array1.length; i ++) {
                            console.log(that.data.table[0].LBANCI)
                            if(that.data.table[0].LBANCI == that.data.array1[i].LNAME) {
                                that.setData({
                                    index1:i
                                })
                            }
                        }
                        my_lid = that.data.table[0].LID
                        app.globalData.notice_lid = that.data.table[0].LID
                        app.globalData.notice_lseq = that.data.table[0].LSEQ
                        app.globalData.notice_lmakeopid = that.data.table[0].LMAKEOPID
                    }
                } else {
                    wx.showModal({
                        title: '提示',
                        content: '获取数据失败',
                        showCancel: false,
                        confirmText: '确定',
                        success(res) {
                            if (res.confirm) {}
                        }
                    })
                }
            },
            fail: function (res) {
                that.setData({
                    loadModal: false
                })
                wx.showModal({
                    title: '提示',
                    content: '访问服务器出错',
                    showCancel: false,
                    confirmText: '确定',
                    success(res) {
                        if (res.confirm) {}
                    }
                })
            }
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})